package com.app.allwe.gui.pic;

import com.app.allwe.gui.SystemUtils;
import org.springframework.beans.factory.annotation.Value;

import javax.swing.*;
import java.awt.*;

public class PicLabel extends JLabel {

    @Value("${pic.backGround.path}")
    private static String picBackGroundPath;

    public static PicLabel createPicLabel() {
        // 设置背景图
        Image backGroundImage = new ImageIcon(picBackGroundPath).getImage();
        // 此处是重点，通过this获取窗体大小来设置图片大小
        ImageIcon backGroundImageIcon = new ImageIcon(backGroundImage);
        backGroundImageIcon.setImage(backGroundImage.getScaledInstance(SystemUtils.getSystemWidth(), SystemUtils.getSystemHeight(), Image.SCALE_AREA_AVERAGING));

        PicLabel picLabel = new PicLabel();
        picLabel.setIcon(backGroundImageIcon);

        return picLabel;
    }
}
